DialogResult result = MessageBox.Show("Do you want to save changes?", "Confirmation", MessageBoxButtons.YesNoCancel); if(result == DialogResult.Yes) { //... } else if (result == DialogResult.No) { //... } else { //... }